addEvent("onInterakcjeWybierzAkcje", true)
addEventHandler("onInterakcjeWybierzAkcje", getRootElement(),
function(id, vehicle)
local veh = getPedOccupiedVehicle(source)
local c = getPedOccupiedVehicle(source)
local recznySalon = getElementData(veh,"recznySalonData")
local modele_zabronione = {

	[463] = true,
	[462] = true,
	[461] = true,
	[581] = true,
	[448] = true,
	[468] = true,
	[471] = true,
	[521] = true,
	[522] = true,
	[523] = true

}

if recznySalon then return end
    if veh then
        if getVehicleController(veh) == source then

            if id == 1 then
            setVehicleEngineState(veh, true)

            elseif id == 2 then
            setVehicleEngineState(veh, false)

            elseif id == 3 then
            setVehicleOverrideLights(veh, 2)

            elseif id == 4 then
            setVehicleOverrideLights(veh, 1)

            elseif id == 5 then
            if modele_zabronione[getElementModel(veh)] then return end
            setVehicleLocked(veh, false)

            elseif id == 6 then
            if modele_zabronione[getElementModel(veh)] then return end
            if recznySalon then return end
            setVehicleLocked(veh, true)

            elseif id == 7 then
            if recznySalon then return end
            if getElementData(veh, "vehicle:block") then outputChatBox("Twój pojazd posiada blokade na koła!", client, 255, 0, 0, true) return end
            setElementFrozen(veh, false)

            elseif id == 8 then
            if recznySalon then return end
            if getElementData(veh, "vehicle:block") then outputChatBox("Twój pojazd posiada blokade na koła!", client, 255, 0, 0, true) return end
            setElementFrozen(veh, true)

            elseif id == 9 then
            setVehicleDoorOpenRatio(veh,0,1,2000)

            elseif id == 10 then
            setVehicleDoorOpenRatio(veh,0,0,2000)

            elseif id == 11 then
            setVehicleDoorOpenRatio(veh,1,1,2000)

            elseif id == 12 then
            setVehicleDoorOpenRatio(veh,1,0,2000)
            
            elseif id == 13 then
                for seat, player in pairs(getVehicleOccupants(veh)) do
                    if player then
                     if seat ~= 0 then
                    setTimer(setControlState, 500, 1, player,"enter_exit", true)
                    setTimer(setControlState, 1500, 1, player,"enter_exit", false)
                    end
                    end
                end       
            elseif id == 14 then
            setElementData(veh,"vehicle:asr","wylaczone")
            setVehicleHandling(veh,"tractionLoss",(getVehicleOriginalProperty(veh,"tractionLoss")))
            elseif id == 15 then
            setElementData(veh,"vehicle:asr","wlaczone")
            setVehicleHandling(veh,"tractionLoss",(getVehicleHandlingProperty(veh,"tractionLoss")+0.2))

	
            end
    else
        if vehicle then
            if isElement(vehicle) then
                if isVehicleLocked(vehicle) then
                setVehicleLocked(vehicle, false)
                else
                setVehicleLocked(vehicle, false)
                end
            end
        end
    end
end
end)

addEventHandler("onVehicleExit", getRootElement(),
function(player, seat)
    if seat == 0 then
    end
end)

addEventHandler("onVehicleStartExit", getRootElement(),
function(player)
    local veh = getPedOccupiedVehicle(player)
    if veh and isVehicleLocked(veh) then 
     exports["cmta-notyfikacje"]:add(player,"Otwórz zamek, aby wysiąść z pojazdu", 5000, 10, tocolor(255, 255, 255), tocolor(255,0,0, 155))
    cancelEvent()
    end
end)

addEventHandler("onVehicleStartEnter", getRootElement(),
function(player)
end)

addEvent("SL:zwieksz", true)
addEventHandler("SL:zwieksz", root, function()
    local veh = getPedOccupiedVehicle(source)
    local s = getVehicleHandlingProperty(veh, "steeringLock")
    setVehicleHandling(veh, "steeringLock", s+5)
end)

addEvent("SL:zmniejsz", true)
addEventHandler("SL:zmniejsz", root, function()
    local veh = getPedOccupiedVehicle(source)
    local s = getVehicleHandlingProperty(veh, "steeringLock")
    setVehicleHandling(veh, "steeringLock", s-5)
end)

addEvent("rh:wyzej", true)
addEventHandler("rh:wyzej", root, function()
    local veh = getPedOccupiedVehicle(source)
    local gora = getElementData(veh, "rh:up") or 0
    local s = getVehicleHandlingProperty(veh, "suspensionForceLevel")
    if tonumber(gora) == 7 then cancelEvent() return end
    setVehicleHandling(veh, "suspensionForceLevel", tonumber(s) + 0.15)
    setElementData(veh, "rh:up", gora+1)
end)

addEvent("rh:nizej", true)
addEventHandler("rh:nizej", root, function()
    local veh = getPedOccupiedVehicle(source)
    local gora = getElementData(veh, "rh:up") or 0
    local s = getVehicleHandlingProperty(veh,"suspensionForceLevel")
    if tonumber(gora) == -5 then cancelEvent() return end
    setVehicleHandling(veh,"suspensionForceLevel",tonumber(s) - 0.15)
    setElementData(veh, "rh:up", gora-1)
end)

addEvent("Naped:Zmien", true)
addEventHandler("Naped:Zmien", root, function()
    local veh = getPedOccupiedVehicle(source)
    local naped_lvl = getElementData(veh, "naped:lvl") or "WYBIERZ NAPĘD"
    if naped_lvl == "RWD" then
    setVehicleHandling(veh, "driveType", "fwd")
    setElementData(veh, "naped:lvl", "FWD")
    elseif naped_lvl == "FWD" then
    setVehicleHandling(veh, "driveType", "awd")
    setElementData(veh, "naped:lvl", "AWD")
    elseif naped_lvl == "AWD" then
    setVehicleHandling(veh, "driveType", "rwd")
    setElementData(veh, "naped:lvl", "RWD")
    elseif naped_lvl == "WYBIERZ NAPĘD" then
    setVehicleHandling(veh, "driveType", "rwd")
    setElementData(veh, "naped:lvl", "RWD")
    end
end)

function getVehicleHandlingProperty ( element, property )
    if isElement ( element ) and getElementType ( element ) == "vehicle" and type ( property ) == "string" then
        local handlingTable = getVehicleHandling ( element ) 
        local value = handlingTable[property] 
 
        if value then
            return value
        end
    end
 
    return false
end

function getVehicleOriginalProperty( element, property )
    if isElement ( element ) and getElementType ( element ) == "vehicle" and type ( property ) == "string" then -- Make sure there's a valid vehicle and a property string
        local modelID = getElementModel ( element )
        local handlingTable = getOriginalHandling ( modelID ) -- Get the handling as table and save as handlingTable
        local value = handlingTable[property] -- Get the value from the table
        
        if value then -- If there's a value (valid property)
            return value -- Return it
        end
    end
    
    return false -- Not an element, not a vehicle or no valid property string. Return failure
end
